import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Demo1 {

    public static void main(String[] args) {
        printDate();
        printFullNum();
        createSevenNum();
        createAutoArray();
        drawTable();
    }

    /**
     * 输入年月日，判断是当年的第几天
     */
    private static void printDate() {
        int year;
        int month;
        int day;
        boolean flag;
        int dates = 0;
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入年份：");
        year = sc.nextInt();
        System.out.print("请输入月份：");
        month = sc.nextInt();
        System.out.print("请输入月份中的日期");
        day = sc.nextInt();

        //判断是否为闰年
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            flag = true;
        } else {
            flag = false;
        }

        //计算前面月份的天数
        switch (month) {
            case 1:
                dates = 0;
                break;
            case 2:
                dates = 31;
                break;
            case 3:
                dates = 59;
                break;
            case 4:
                dates = 90;
                break;
            case 5:
                dates = 120;
                break;
            case 6:
                dates = 151;
                break;
            case 7:
                dates = 181;
                break;
            case 8:
                dates = 212;
                break;
            case 9:
                dates = 243;
                break;
            case 10:
                dates = 273;
                break;
            case 11:
                dates = 304;
                break;
            case 12:
                dates = 334;
                break;
        }

        //如果为闰年且为二月份之后的月份，天数加一
        if (flag && month > 2) {
            dates++;
        }
        System.out.println("这是今年的第" + (dates + day) +"天");
    }

    /**
     * 打印1000以内的所有完数
     */
    private static void printFullNum() {
        for (int i = 2; i < 1000; i++) {
            int sum = 0;
            for (int j = 1; j < i; j++) {
                if (i % j == 0) {   //判断是否为因子，如果是则加入总和中
                    sum += j;
                }
            }
            if (sum == i) { //判断是否为完数
                System.out.println(i);
            }
        }
    }

    /**
     * 随机生成6个不重复的红球和1个篮球
     */
    private static void createSevenNum() {
        //生成随机的6个红球
        Random random = new Random();
        int[] reds = new int[6];
        reds[0] = (random.nextInt(33) + 1);
        for (int i = 1; i < reds.length; i++) {
            int temp = random.nextInt(33) + 1;
            for (int j = 0; j < i; j++) {
                if (temp == reds[j]) {
                    i--;
                    break;
                } else {
                    reds[i] = temp;
                }
            }
        }
        for (int red : reds) {
            System.out.print(red + "\t");
        }
        System.out.println("");

        //生成随机的一个篮球
        int blue = random.nextInt(16) + 1;
        System.out.println("蓝球号码：" + blue);
    }

    /**
     * 创建自动扩容的数组
     */
    private static void createAutoArray() {
        int arrLength;
        int count = 0;
        int a = 0;
        System.out.print("请输入你想创建的数组长度：");
        Scanner sc = new Scanner(System.in);
        arrLength = sc.nextInt();
        int[] arr = new int[arrLength];
        outer: while (true) {
            int length = arr.length;
            Scanner sc1 = new Scanner(System.in);
            for (int i = a; i < length; i++) {
                System.out.println("请输入要添加的数字：");
                arr[i] = sc1.nextInt();
                count++;

                if ((double)count / length > 0.8) {
                    arr = Arrays.copyOf(arr, (int) (arr.length * 1.5));
                    a = i + 1;
                    break;
                }
            }
            System.out.println("当前数组为：");
            System.out.println(Arrays.toString(arr)+ "\n");
            System.out.println("如果要结束请输入Q，要继续输入任意键：");
            if (sc1.next().equals("Q")) {
                break;
            }
        }
        System.out.println("");
        System.out.println("最终数组为：");
        System.out.println(Arrays.toString(arr));
    }

    /**
     * 根据要求生成并绘制五子棋盘
     */
    private static void drawTable() {
        char[][] table = new char[17][17];
        char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

        //创建棋盘
        for (int i = 0; i < 17; i++) {
            for (int j = 0; j < 17; j++) {
                if (i == 0 && j == 0) {
                    continue;
                }
                if (i == 0) {
                    table[i][j] = chars[j - 1];
                } else if (j == 0) {
                    table[i][j] = chars[i - 1];
                } else {
                    table[i][j] = '+';
                }
            }
        }

        //绘制棋盘
        for (char[] value : table) {
            for (int j = 0; j < table.length; j++) {
                System.out.print(value[j] + "\t");
            }
            System.out.println();
        }
    }
}
